<?php

namespace App\Http\Requests;

use App\Util\Result;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;

class PopUpRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'img_url' => 'required',
            'http_url' => 'bail|required|active_url'
        ];
    }

    /**
     * 获取已定义验证规则的错误消息。
     *
     * @return array
     */
    public function messages()
    {
        return [
            'img_url.required' => '请上传图片',
            'http_url.required'  => '请填写链接',
            'http_url.active_url'  => '请填写正确的链接地址',
        ];
    }

    /**
     * {@inheritdoc}
     */
    protected function formatErrors(Validator $validator)
    {
        return Result::failure( $validator->errors()->first() )->getResult();
    }
}
